<template>
        <el-dialog top="5%" title="新增" v-model="editFormVisible" :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="140px">
                <el-form-item label="合同编号">
                    <el-input v-model="form.FNo"></el-input>
                </el-form-item>
                <el-form-item label="客户名称"  prop="FCustID">
                    <sy-select v-model="form.FCustID" remote
                               optionData="server/customer/Customer.ashx?cmd=GetOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="项目申报名称"  prop="FProjectName">
                    <sy-select v-model="form.FProjectName"  valueKey="FName"   @change="FProjectNameChange"
                               :optionData="'server/customer/Project.ashx?cmd=GetOptions&FCustID='+(form.FCustID?form.FCustID:-1)">
                    </sy-select>
                </el-form-item>
                <el-form-item label="申报等级"  prop="FGrade">
                    <el-select filterable  v-model="form.FGrade" placeholder="请选择" style="width: 100%">
                        <el-option label="国家级" value="国家级"></el-option>
                        <el-option label="省级" value="省级"></el-option>
                        <el-option label="市级" value="市级"></el-option>
                        <el-option label="县级" value="县级"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="申报资金种类"  prop="FBankrollType">
                    <sy-select v-model="form.FBankrollType"  valueKey="FName"
                               optionData="server/system/SetType.ashx?cmd=GetOptions&FType=1">
                    </sy-select>
                </el-form-item>
                <el-form-item label="资金年限">
                    <el-date-picker type="year" placeholder="开始年限" v-model="form.FDeadlineBeg"  style="width: 120px"></el-date-picker>
                    <span>---</span>
                    <el-date-picker type="year" placeholder="结束年限" v-model="form.FDeadlineEnd"  style="width: 120px"></el-date-picker>
                </el-form-item>
                <el-form-item label="合同点数(%)" prop="FCustCommission">
                    <el-input @change="changeCommission" v-model="form.FCustCommission"></el-input>
                    <!--<el-input-number :controls="false" @change="changeCommission" :min="0" v-model="form.FCustCommission" style="width: 100%"></el-input-number>-->
                </el-form-item>
                <el-form-item label="获得扶持资金总额(万元)" prop="FAmount">
                    <el-input @change="changeAmount" v-model="form.FAmount"></el-input>
                    <!--<el-input-number  :controls="false" @change="changeAmount" :min="0" v-model="form.FAmount" style="width: 100%"></el-input-number>-->
                </el-form-item>
                <el-form-item label="应得咨询费总额(万元)">
                    <el-input readonly v-model="form.ToAmount"></el-input>
                </el-form-item>
                <el-form-item label="实际咨询费总额(万元)" prop="FActAmount">
                    <el-input v-model="form.FActAmount"></el-input>
                    <!--<el-input-number  :controls="false" :min="0" v-model="form.FActAmount" style="width: 100%"></el-input-number>-->
                </el-form-item>
                <el-form-item label="付款方式">
                    <el-radio-group v-model="form.FPayWay">
                        <el-radio label="第一笔"></el-radio>
                        <el-radio label="每一笔"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="业务提成">
                    <el-input v-model="form.FCommission"></el-input>
                </el-form-item>
                <el-form-item label="合同签订时间">
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.FCompletedDate"  style="width: 100%"></el-date-picker>
                </el-form-item>
                <el-form-item label="合同完成时间">
                    <el-date-picker type="date" placeholder="选择日期" v-model="form.FToCompletedDate"  style="width: 100%"></el-date-picker>
                </el-form-item>
                <el-form-item label="咨询师">
                    <el-input v-model="form.FCounselor"></el-input>
                </el-form-item>
                <el-form-item label="更换咨询师">
                    <el-input v-model="form.FSecCounselor"></el-input>
                </el-form-item>
                <el-form-item label="跟单员">
                    <sy-select  v-model="form.FUserID"
                               optionData="server/system/User.ashx?cmd=GetUserOptions">
                    </sy-select>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="form.FNote"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button v-if="authEdit" type="primary" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
</template>

<script>
    import util from '../../common/util'
    import mixin from '../../common/mixin'
    export default {
        mixins: [mixin],
        data() {
            return {
                authEdit:false,
                form: {},
                rules: {
                    FCustCommission:[ { validator: this.isFloat, trigger: 'change' }],
                    FAmount:[ { validator: this.isFloat, trigger: 'change' }],
                    FActAmount:[ { validator: this.isFloat, trigger: 'change' }]
                },
                loading:false,
                editFormVisible:false
            }
        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record,authEdit) {
                this.authEdit = authEdit
                this.editFormVisible = true
                this.form = Object.assign({},record,{FIncomeInfo:"",FExpendInfo:"",Collections:""})
            },
            _openAdd() {
                this.authEdit = true
                this.editFormVisible = true
                this.form = {FID:0,FGrade:"",FPayWay:"",FToCompletedDate:null,FCompletedDate:"",FBankrollType:"",
                    FDeadlineBeg:null,FDeadlineEnd:null,FCustID:null,FProjectID:0,ToAmount:0,FAmount:0,FCustCommission:0,FActAmount:0}
            },
            save:function () {
                let url = "server/customer/Contract.ashx?cmd=Save"
                util.saveForm(url,this.$refs.form,this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    this.editFormVisible = false
                    this.$emit("onSaveSuc",this.form)
                })
            },
            FProjectNameChange(val,record,key){
                //反了，应该是选ID，名字带出来的
                this.form.FProjectID = record.FID
            },
            changeAmount(val){
                this.form.ToAmount = val *  this.form.FCustCommission / 100;
            },
            changeCommission(val){
                this.form.ToAmount = val *  this.form.FAmount / 100;
            }
        },
        mounted() {

        }
    }
</script>
